<template>
  <!-- 班级信息页面 -->
  <div class="app-container">
    <!--部门数据-->

    <searchForm
      :formOptions="formOptions"
      @onSearch="onSearch"
      @onReset="onReset"
      :formLabelWidth="formLabelWidth"
      v-show="showSearch"
    >
    <el-form-item label="所在院部：">
            <el-select v-model="queryParams.deptId" placeholder="请选择" clearable class="elSelect" @change="handleChange"
              style="width: 100%">
              <el-option v-for="item in deptOptions" :key="item.deptId" :label="item.deptName"
                :value="item.deptId"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="所选专业：">
            <el-select v-model="queryParams.specialityId" clearable placeholder="请选择" style="width: 200px">
              <el-option v-for="item in professionList" :key="item.VALUE" :label="item.TITILE"
                :value="item.VALUE"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所在年级：">
            <el-select v-model="queryParams.gradeId" clearable placeholder="请选择" style="width: 200px"  @change="changeGrade">
              <el-option v-for="item in gradeList" :key="item.VALUE" :label="item.TITILE"
                :value="item.VALUE"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所在班级：">
            <el-select v-model="queryParams.gradeId" clearable placeholder="请选择" style="width: 200px"  @change="changeGrade">
              <el-option v-for="item in classList" :key="item.VALUE" :label="item.TITLE"
                :value="item.VALUE"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="性别：">
              <el-select v-model="queryParams.sex" placeholder="请选择审批状态" style="width: 100%" clearable>
                <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          <el-form-item label="异动类别：">
              <el-select v-model="queryParams.ydlbdm" placeholder="请选择审批状态" style="width: 100%" clearable>
                <el-option v-for="dict in dict.type.sys_xdlbdm_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          <el-form-item label="类型：">
              <el-select v-model="queryParams.zd" placeholder="请选择类型" style="width: 100%" clearable>
                <el-option v-for="dict in dict.type.sys_studentchange_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          <el-form-item label="是否立即生效：">
              <el-select v-model="queryParams.sfljsx" placeholder="请选择类型" style="width: 100%">
                <el-option v-for="dict in dict.type.sys_studentchange_sfsx" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          <el-form-item label="操作时间：">
            <el-date-picker
                  class="elSelect"
                  v-model="queryParams.czsj"
                  type="date"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                ></el-date-picker>
            </el-form-item>

    </searchForm>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['basic:changeRecord:export']"
            >导出</el-button>
   
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      :data="roleList"
      @selection-change="handleSelectionChange"
      v-loading="loading"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="所在院系"
        prop="collegeName"
        align="center"
        width="130"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="专业"
        prop="specialityName"
        align="center"
        width="130"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="年级"
        prop="gradeName"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="班级"
        prop="className"
        align="center"
        width="130"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="注册号"
        prop="zch"
        align="center"
        width="130"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="姓名"
        prop="studentName"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="性别"
        prop="sex"
        align="center"
        :show-overflow-tooltip="true"
      >
      <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_user_sex"
            :value="scope.row.sex"
          ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="异动前名称"
        prop="ydqmc"
        :show-overflow-tooltip="true"
        align="center"
        width="100"
      />
      <el-table-column
        label="异动后名称"
        prop="ydhmc"
        :show-overflow-tooltip="true"
        align="center"
        width="100"
      />
      <!-- <el-table-column
        label="异动类别代码"
        prop="ydlbdm"
        :show-overflow-tooltip="true"
        align="center"
        width="100"
      /> -->
      <el-table-column
        label="异动类别名称"
        prop="ydlbmc"
        :show-overflow-tooltip="true"
        align="center"
        width="100"
      />
      <!-- <el-table-column
        label="异动原因代码"
        :show-overflow-tooltip="true"
        prop="ydyydm"
        align="center"
        width="160"
      /> -->
      <el-table-column
        label="异动原因名称"
        :show-overflow-tooltip="true"
        prop="ydyymc"
        align="center"
        width="160"
      />
      <el-table-column
        label="类型"
        :show-overflow-tooltip="true"
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_studentchange_type"
            :value="scope.row.zd"
          ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="是否立即生效"
        :show-overflow-tooltip="true"
        prop="sfljsx"
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_studentchange_sfsx"
            :value="scope.row.sfljsx"
          ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="申请学年学期代码"
        :show-overflow-tooltip="true"
        prop="sqxnxqdm"
        align="center"
        width="130"
      />
      <el-table-column
        label="生效日期"
        :show-overflow-tooltip="true"
        prop="sxrq"
        align="center"
        width="130"
      />
      <el-table-column
        label="操作时间"
        prop="czsj"
        align="center"
        width="100"
      />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
      
      <script>
// import { deptTreeSelect } from "@/api/system/user";
import { changeRecordList } from "@/api/flowable/transaction.js";
import { getGradeSelect } from "@/api/information/gradeInfor";
import { getSpecialityByDeptId } from "@/api/information/unitMajor";
import { getClassSelect } from "@/api/information/classInfor";
import {
  collegeSelect
} from "@/api/information/studentInfor"
import Validators from "@/utils/validate.js";

import { getDicts } from "@/api/system/dict/type";
import searchForm from "@/components/Search/searchForm.vue";
export default {
  name: "Role",
  dicts: ["sys_normal_disable", "bc_speciality_type", "sys_studentchange_sfsx",'sys_user_sex','sys_xdlbdm_type', 'sys_studentchange_type'],
  components: { searchForm },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 部门数据
      professionList: [],
      // 入学年级数据
      gradeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      formLabelWidth: "110px",
      formOptions: [
      {
          label: "注册号",
          prop: "zch",
          element: "el-input",
          placeholder: "请输入注册号",
        },
        {
          label: "姓名",
          prop: "studentName",
          element: "el-input",
          placeholder: "请输入姓名",
        },
       
      ],
      deptOptions: [],
      collegeSelectList: [],
      classList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        deptId: "",
        classNumber: "",
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  created() {
    this.getDeptTree()
    this.getList();
    this.getGrade();
  },
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      this.queryParams = Object.assign(this.queryParams, val);
      // console.log(arr);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      console.log(data);
      this.queryParams.deptId = "";
      this.queryParams = Object.assign(this.queryParams, data);
      this.getList();
    },
    // tree树形选中的值
    handleNodeClick(data) {
      this.deptId = data.id;
      this.deptNameTree = data.label;
      this.queryParams.deptId = data.id;
      this.getList();
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      collegeSelect().then((response) => {
        console.log(response);
        this.deptOptions = response.data;
        this.formOptions[0].options = this.deptOptions.map(item => {
        return {
          value: item["deptId"],
          label: item["deptName"]
        };
      })
        // this.queryParams.deptId = response.data[0].id;
      });
    },
    handleChange(value) {
      // if (value) {
      //   this.form.deptId = value[value.length - 1];
      //   this.getSpeciality();
      // }
      //   this.queryParams.deptId = value;
      this.form.specialityId = "";

      this.getSpeciality();
     
    },
    getSpeciality() {
      getSpecialityByDeptId({ deptId: this.queryParams.deptId }).then((res) => {
        this.professionList = res.data;
      });
    },

    /** 查询角色列表 */
    getList() {
      this.loading = true;
      changeRecordList(this.queryParams).then((response) => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取部门信息
    // department() {
    //   collegeSelect().then((res) => {
    //     this.collegeSelectList = res.data;
    //     console.log(this.deptOptions, " this.deptOptions");
    //     // this.queryParams.deptId = res.data[0].id
    //   });
    // },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
    },
    getClassList() {
      getClassSelect({
        gradeId: this.queryParams.gradeId,
        specialtyId: this.queryParams.specialityId
      }).then(res => {
        this.classList = res.data;
        console.log(this.classList, "班级");
      });
    },
       // 获取班级拉下树
       changeGrade(value) {
      console.log(value, "ceeee");
      if (value != undefined) {
        if (this.queryParams.specialityId && this.queryParams.gradeId) {
          this.getClassList();
          this.classList = [];
          this.queryParams.classId = "";
        } else {
          if (!value) {
            this.classList = [];
            this.form.classId = "";
          }
        }
      } else {
        this.getClassList();
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.name = selection.map((item) => item.name);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handleExport() {
      this.download(
        "/basic/changeRecord/export",
        this.queryParams,
        `异动记录${new Date().getFullYear()}-${new Date().getMonth() +
        1}-${new Date().getDate()}.xlsx`
      );
    },

    // 获取年级信息
    getGrade() {
      getGradeSelect().then((res) => {
        console.log(res);
        this.gradeList = res.data;
      });
    },
  },
};
</script>